﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BLToolkit.DataAccess;
using Clipping.Utils;
using System.IO;
using BLToolkit.Validation;

namespace Clipping.Utils
{
    [TableName(Name = "SysSettings")]
    public class SYSSETTINGS:ModelBase<SYSSETTINGS>
    {
        class SETTINGSUpdater : DBPartUpdater<SETTINGSUpdater>
        {
            static SETTINGSUpdater()
            {
                Actions[typeof(SETTINGSUpdater)] = new List<UpdateAction>();

                #region 数据库升级脚本

                Versions[typeof(SETTINGSUpdater)] = 0;

                #region 创建表 Keywords

                AddUpdateAction(typeof(SETTINGSUpdater), @"CREATE TABLE SysSettings(
Key VARCHAR2(100) NOT NULL,
Value VARCHAR2(100) NOT NULL
);      
");
                #endregion

                #endregion
            }
        }

        static SYSSETTINGS()
        {
            string dbPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DB", "SysSettings.db");
            var connPool = DBHelper.CreateDBConnectionPool<SysSettingsDBUpdater>(dbPath, 10);
            DBHelper.UpdateTableSchema<SETTINGSUpdater>(connPool);
        }

        [PrimaryKey(0), Required]
        public string Key { get; set; }
        /// <summary>
        /// 类别ID
        /// </summary>
        [Required]
        public string Value { get; set; }
    }

    public class SysSettingsDBUpdater : DBUpdater
    { 
        /// <summary>
        /// 升级脚本初始化
        /// 所有的数据库操作语句都集中在这里，方便数据库自动升级
        /// </summary>
        static SysSettingsDBUpdater()
        {
            Actions[typeof(SysSettingsDBUpdater)] = new List<UpdateAction>();

            #region 数据库升级脚本

            Versions[typeof(SysSettingsDBUpdater)] = 0;

            #endregion
        }
    }


    [TableName(Name = "UserSettings")]
    public class USERSETTINGS : ModelBase<USERSETTINGS>
    {
        class SETTINGSUpdater : DBPartUpdater<SETTINGSUpdater>
        {
            static SETTINGSUpdater()
            {
                Actions[typeof(SETTINGSUpdater)] = new List<UpdateAction>();

                #region 数据库升级脚本

                Versions[typeof(SETTINGSUpdater)] = 0;

                #region 创建表 Keywords

                AddUpdateAction(typeof(SETTINGSUpdater), @"CREATE TABLE UserSettings(
Key VARCHAR2(100) NOT NULL,
Value VARCHAR2(100) NOT NULL
);      
");
                #endregion

                #endregion
            }
        }

        static USERSETTINGS()
        {
            string dbPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DB", "UserSettings.db");
            var connPool = DBHelper.CreateDBConnectionPool<UserSettingsDBUpdater>(dbPath, 10);
            DBHelper.UpdateTableSchema<SETTINGSUpdater>(connPool);
        }

        [PrimaryKey(0), Required]
        public string Key { get; set; }
        /// <summary>
        /// 类别ID
        /// </summary>
        [Required]
        public string Value { get; set; }
    }

    public class UserSettingsDBUpdater : DBUpdater
    {
        /// <summary>
        /// 升级脚本初始化
        /// 所有的数据库操作语句都集中在这里，方便数据库自动升级
        /// </summary>
        static UserSettingsDBUpdater()
        {
            Actions[typeof(UserSettingsDBUpdater)] = new List<UpdateAction>();

            #region 数据库升级脚本

            Versions[typeof(UserSettingsDBUpdater)] = 0;

            #endregion
        }
    }
}
